/*
 * File:   10959.cpp
 * Author: xerxes
 *
 * Created on September 16, 2011, 5:36 PM
 *
 * I have not failed, I have just found 10000 ways that won't work.
 */

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait(double seconds) {
    double endtime = clock()+(seconds * CLOCKS_PER_SEC);
    while (clock() < endtime) {
        ;
    }
}

int nperson;
int nedges;
vector< VI > vi;
int flag[1001][1001];
string ss = "";

inline void Read() {
    SET(flag, 0);
    CI(nperson);
    CI(nedges);
    vi.assign(nperson + 5, VI());

    fo(i, 0, nedges) {
        int x, y;
        CI(x);
        CI(y);
        if (flag[x][y])continue;
        vi[x].pb(y);
        vi[y].pb(x);
        flag[x][y] = flag[y][x] = 1;
    }
}
int vis[1010];

inline void bfs() {
    SET(vis, 0);
    queue< int > q;
    q.push(0);
    vis[0] = 1;

    while (q.empty() == false) {
        int father = q.front();
        q.pop();

        for (int i = 0, j = SZ(vi[father]); i < j; ++i) {
            int child = vi[father][i];
            if (vis[child])continue;

            q.push(child);
            vis[child] = vis[father] + 1;
        }
    }
}

inline void Proc() {
    bfs();
    cout << ss;

    fo(i, 1, nperson) {
        cout << vis[i] - 1 << "\n";
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in", "rt", stdin);
#endif
    int cases = 1;

    for (CI(cases); cases; --cases) {
        Read();
        Proc();
        ss = "\n";
    }

    return 0;
}


